package com.songhq.data.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.songhq.data.bean.FatherGrade;
import com.songhq.data.bean.PageVO;
import com.songhq.data.bean.Response;
import com.songhq.data.constant.ServiceCode;
import com.songhq.data.log.util.LogUtil;
import com.songhq.data.service.FatherGradeService;


@RestController
@RequestMapping("/fatherGrade")
public class FatherGradeController {
	
	
	
	@Autowired
	private  FatherGradeService fatherGradeService;
	

    /**
     * 列表
     * @param fatherGrade
     * @return
     */
    @GetMapping(value = "/list")
    public Response listFatherGrades( FatherGrade fatherGrade) {
    	try {
    		LogUtil.info("FatherGradeController.listFatherGrades|fatherGrade = "+ JSON.toJSONString(fatherGrade));
    		PageVO result = fatherGradeService.listFatherGrades(fatherGrade);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "FatherGradeController.listFatherGrades");
            return Response.error(ServiceCode.FAIL, "查询列表异常");
        }
    }
    
    /**
     * 查看详情
     * @param fatherGradeId
     * @return
     */
    @GetMapping(value = "/getOne")
    public Response getOneFatherGrade( String fatherGradeId) {
    	try {
    		LogUtil.info("FatherGradeController.getOneFatherGrade|fatherGradeId = " + fatherGradeId);
    		FatherGrade result = fatherGradeService.getOneFatherGrade(fatherGradeId);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "FatherGradeController.getOneFatherGrade");
            return Response.error(ServiceCode.FAIL, "查询详情异常");
        }
    }
    
   
    @GetMapping(value = "/save")
    public Response saveFatherGrade( FatherGrade fatherGrade) {
    	try {
    		LogUtil.info("FatherGradeController.saveFatherGrade|fatherGrade = " + JSON.toJSONString(fatherGrade));
    		fatherGradeService.saveFatherGrade(fatherGrade);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FatherGradeController.saveFatherGrade");
            return Response.error(ServiceCode.FAIL, "新增异常");
        }
    }
    
    @GetMapping(value = "/update")
    public Response updateFatherGrade( FatherGrade fatherGrade) {
    	try {
    		LogUtil.info("FatherGradeController.updateFatherGrade|fatherGrade = " + JSON.toJSONString(fatherGrade));
    		fatherGradeService.updateFatherGrade(fatherGrade);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FatherGradeController.updateFatherGrade");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }
    @GetMapping(value = "/delete")
    public Response deleteFatherGrade( FatherGrade fatherGrade) {
    	try {
    		LogUtil.info("FatherGradeController.updateFatherGrade|fatherGrade = " + JSON.toJSONString(fatherGrade));
    		fatherGradeService.deleteFatherGrade(fatherGrade);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "FatherGradeController.updateFatherGrade");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }

}
